#!/usr/bin/env bash

VIRTUAL_ENVIRONMENT_NAME=$1
PYTHON_VERSION=$2

############判断虚拟环境是否存在##################
ENVS=`conda info --envs`
result=$(echo ${ENVS} | grep "${VIRTUAL_ENVIRONMENT_NAME}")

if [[ "${result}" != "" ]]
then
    echo "Conda Envs ${VIRTUAL_ENVIRONMENT_NAME} Exist!!!"
    exit 1
fi
###############################################



#################虚拟环境初始化##################
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

echo y | conda create --name ${VIRTUAL_ENVIRONMENT_NAME} python=${PYTHON_VERSION}
source activate ${VIRTUAL_ENVIRONMENT_NAME}

# 生成依赖包文件
pip install --upgrade pip
pip freeze > dependency_package.txt
pip install -r dependency_package.txt
source deactivate
rm dependency_package.txt
###############################################